home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple II Magazines (PO)
/
Nibble Volume 10, No. 05 (1989-05)(MicroSPARC)(Side A).zip
/
Nibble Volume 10, No. 05 (1989-05)(MicroSPARC)(Side A).po
/
TEXT.CRUNCH.S
< prev
next >
Wrap
Text File
|
1996-12-24
|
4KB
|
183 lines
********************************
* TEXT.CRUNCH Source Code *
* by Howard Huang *
* Copyright (c) 1985 *
* by MicroSPARC, Inc. *
* Concord, MA 01742 *
* *
* Assembler: MERLIN *
********************************
ORG $6000
*
* --> Equates
*
DONE = $0 ;Flag for last letter
TEMP = $2 ;Temporary storage
COUNTER = $3 ;Counter for groups of chars
ALLFLAG = $4 ;Include lowercase?
CODE = $6 ;Text buffer address
TEXT = $8 ;Text to be crunched
LEFT = $A ;Shift left counter
RIGHT = $B ;Shift right counter
*==============
* PROGRAM START
*==============
*
* --> Initialize
*
CRUNCH LDY #$FF
STY DONE ;Reset DONE flag
INY
LDA ALLFLAG
BNE ALLCHARS ;If ALLFLAG = 1, do lowercase
*======================
* CRUNCH UPPERCASE ONLY
*======================
BEGIN LDA #1
STA COUNTER ;First char in 4-char group
LDA (TEXT),Y
BNE UPPERC ;Not end yet
JMP QUIT1 ;Exit
UPPERC LDA (TEXT),Y ;Get character
LDX COUNTER
AND MASK1-1,X ;Erase unwanted bits
PHA
TXA
ASL
STA LEFT ;Number of times to shift
PLA
JSR MOVELEFT ;Go ahead and ASL
JSR INCTEXT ;Get next character
LDX COUNTER
AND MASK2-1,X ;Erase some bits
PHA
LDA #3
SEC
SBC COUNTER
ASL
STA RIGHT ;How many times to shift right
PLA
JSR MOVERGHT ;Shift rightwards
JSR COMBINE ;Form an encoded byte
INC COUNTER ;Next char
LDA COUNTER
CMP #4
BNE UPPERC ;Still in same group of 4
JSR INCTEXT ;Start another group
JMP BEGIN ;Do next group
*
* --> Table of MASKS
*
MASK1 DFB $3F,$0F,$03
MASK2 DFB $3F,$3C,$3F
*============================
* CRUNCH UPPER AND LOWER CASE
*============================
ALLCHARS LDA #1
STA LEFT
LDA #6
STA RIGHT ;Set initial values
LDA #7
STA COUNTER ;Do 8 character group
LDA (TEXT),Y
BEQ QUIT1 ;No more text
DOONE LDA (TEXT),Y ;Get char
JSR MOVELEFT ;Shift leftwards
JSR INCTEXT1 ;Get next char
JSR MOVERGHT ;Move rightwards
JSR COMBINE ;Form encoded byte
INC LEFT
DEC RIGHT ;Prepare for next char
DEC COUNTER
BNE DOONE ;Still in same group
JSR INCTEXT1 ;Get first char of next group
JMP ALLCHARS ;Crunch next group
*============
* SUBROUTINES
*============
*
* --> Shift bits to the right
*
MOVERGHT LDX RIGHT
RGHT:1 BEQ ENDRIGHT ;No more shifting
LSR ;Shift
DEX
JMP RGHT:1
ENDRIGHT RTS
*
* --> Shift bits to the left and save result
*
MOVELEFT LDX LEFT
LEFT:1 BEQ ENDLEFT
ASL
DEX
JMP LEFT:1
ENDLEFT STA TEMP ;Save the result
RTS
*
* --> Increment TEXT for uppercase routine
*
INCTEXT INC TEXT ;Push up
BNE INCRET
INC TEXT+1 ;Next page
INCRET LDA (TEXT),Y ;Get character
STA DONE
RTS
*
* --> Increment TEXT for lowercase routine
*
INCTEXT1 JSR INCTEXT
AND #$7F ;Erase first bit
RTS
*
* --> Combine bytes to form one encoded byte
*
COMBINE ORA TEMP ;Combine
STA (CODE),Y ;Save
INC CODE ;Next memory location
BNE RETURN
INC CODE+1 ;Next page
RETURN LDA DONE
BEQ QUIT ;No more to crunch
RTS
*
* --> End crunching
*
QUIT PLA
PLA ;Pull off call
QUIT1 LDA #0
STA (CODE),Y ;Zero last byte
RTS
LST OFF